<?php
	/*ini_set("display_errors","1");
	error_reporting(E_ALL);*/
	require_once("cClientePhone.php");
	require_once("cAuditoriaPhone.php");
	
	$alias = trim($_REQUEST['alias']);
	$password = trim($_REQUEST['password']);
	
	if ($alias == '' || $password == '') {
		header("Location: errorCell.php?error=0");
		exit();
	}

	$loginClass = new CLoginPhone();
	$loginClass->alias = $alias;
   	$loginClass->password = $password;
   	$loginClass = BykomClientePhone::LoginPhone($loginClass);
   	if ($loginClass->errorCode != 0) {
   		header("Location: errorCell.php?error=" . $loginClass->errorCode);
   		exit();
   	}
   	if ($loginClass->cantidadSubCuentas == 0) {
   		header("Location: errorCell.php?error=50");
   		exit();
   	}

	// AGREGAMOS EL EVENTO A LA AUDITORIA
	$auditoria = new CAuditoriaPhone();
	$auditoria->tablaId = $loginClass->tablaId;
	$auditoria->objetivo = $loginClass->objetivo;
	$auditoria->tipoAuditoria = 1; /*Acceso*/
	$auditoria->tipoVinculo = 2; /*Celular*/
	$auditoria->fechaYHora = date("Y-m-d H:i:s");
	$auditoria->ip = HOSTCLIENT_NO_SSL;
	$auditoria->ip = "";
	$auditoria = $auditoria->persistir( $auditoria );

   	//Params
   	$params = "?tablaId=" . $loginClass->tablaId."&objetivo=".$loginClass->objetivo."&objetivoDB=".$loginClass->objetivoDB."&cuentaFk=".$loginClass->cuentaFk;
   	//Redirection
   	//	print_r($loginClass);exit;
   	if ($loginClass->objetivoDB == 1) {
   		if ($loginClass->cantidadSubCuentas > 1) {
   			$locationByType = "fijosFilterCell.php";
   		} else {
   			$locationByType = "fijosFilterCell.php";
   		}
   	} else if ($loginClass->objetivoDB == 2) {
   		$locationByType = "movilCell.php";
   	} else if ($loginClass->objetivoDB == 3) {
   		$locationByType = "flotaCell.php";
   	} else if ($loginClass->objetivoDB == 5) {
   		//$locationByType = "dealerFilterCell.php";
   		$locationByType = "FilterCell.php";
	}
   header("Location: " . $locationByType . $params);
?>



